<?php
include "config.php";//apikey配置文件
include "jd/JdClient.php";//请求文件
include "jd/RequestCheckUtil.php";//请求文件
include "jd/request/UnionOpenPromotionByunionidGetRequest.php";//接口参数


global $AppKey;
global $AppSecret;
$AppKey = $ApiConfig["AppKey"];
$AppSecret = $ApiConfig["AppSecret"];


// echo promotion_byunionid_get(1000130713,123456,"https://u.jd.com/BIUP1cW");

function promotion_byunionid_get($unionId,$positionid,$url){//
	global $AppKey;
	global $AppSecret;
	
	$c = new JdClient();
	$c->appKey = $AppKey ;
	$c->appSecret = $AppSecret;
	$res = new UnionOpenPromotionByunionidGetRequest();
	$promotionCodeReq= array();
	$promotionCodeReq["materialId"] = $url;//推广物料url，例如活动链接、商品链接等；不支持仅传入skuid
	$promotionCodeReq["unionId"] = $unionId;//联盟id,Number
	$promotionCodeReq["positionId"] = $positionid;//推广位id,Number
	$res -> setPromotionCodeReq($promotionCodeReq);
	$resp = $c->execute($res) -> jd_union_open_promotion_byunionid_get_responce;
	return $resp -> getResult;

	//{"code":200,"data":{"shortURL":"https://u.jd.com/BIUP1cW"},"message":"success","requestId":"o_0b648113_l0davi7j_64445584"}
	//{"code":2001703,"message":"您填写的原始链接materialId不符合要求！","requestId":"o_0b73145e_l0daw19j_64402262"}
}